using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;

[CustomEditor(typeof(CameraController))]
public class CameraControllerInspector : Editor
{
    private SerializedProperty cameraShifters;
    private ReorderableList reorderableList;
    private void OnEnable()
    {
        cameraShifters = serializedObject.FindProperty("cameraShifterList");
        reorderableList = new ReorderableList(serializedObject, cameraShifters);
        //设置单个元素的高度
        reorderableList.elementHeight = 30;

        //绘制单个元素
        reorderableList.drawElementCallback =
            (rect, index, isActive, isFocused) => {
                var element = cameraShifters.GetArrayElementAtIndex(index);
                rect.height -= 4;
                rect.y += 2;
                EditorGUI.PropertyField(rect, element);
            };

        //背景色
        reorderableList.drawElementBackgroundCallback = (rect, index, isActive, isFocused) => {
            GUI.backgroundColor = Color.cyan;
        };

        //头部
        reorderableList.drawHeaderCallback = (rect) =>
            EditorGUI.LabelField(rect, cameraShifters.displayName);
    }

    public override void OnInspectorGUI()
    {
        EditorGUILayout.Space();
        serializedObject.Update();
        reorderableList.DoLayoutList();
        serializedObject.ApplyModifiedProperties();
        
    }
    
}